package com.dk.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dk.mapper.PersonRoleMapper;
import com.dk.mapper.RoleMenuMapper;
import com.dk.mapper.TRoleMapper;
import com.dk.pojo.RoleMenuExample;
import com.dk.pojo.TRole;
import com.dk.service.rolerservice;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
@org.springframework.stereotype.Service
public class rolerserviceImpl implements rolerservice {
    @Autowired
    private TRoleMapper tRoleMapper;
    @Autowired
    private RoleMenuMapper roleMenuMapper;
    @Autowired
    private PersonRoleMapper personRoleMapper;
    @Override


    public List<TRole> selecteGetInfo() {

        return tRoleMapper.selectByExample(null);
    }

    @Override
    public boolean insertActor(TRole role, Integer[] id) {
        try {
            Integer i = tRoleMapper.insertreturnAid(role);
            Integer aid = role.getRoleId();
            System.out.println(aid);
            Integer ii = roleMenuMapper.insertBatch(aid,id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public TRole selectbyaid(Integer roleId) {
        return tRoleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public boolean updategetinfo(Integer[] id, TRole tRole) {
        try {
            int i = tRoleMapper.updateByPrimaryKeySelective(tRole);
            RoleMenuExample ahe = new RoleMenuExample();
            RoleMenuExample.Criteria criteria = ahe.createCriteria();
            criteria.andRoleIdEqualTo(tRole.getRoleId());
            int i1 = roleMenuMapper.deleteByExample(ahe);

            Integer integer = roleMenuMapper.insertBatch(tRole.getRoleId(), id);

            return true;
        }catch (Exception e){
            e.printStackTrace();;
            throw e;
        }
    }

    @Override
    public boolean deleteinfo(Integer roleId) {
        int i = tRoleMapper.deleteByPrimaryKey(roleId);
        RoleMenuExample ahe = new RoleMenuExample();
        RoleMenuExample.Criteria criteria = ahe.createCriteria();
        criteria.andIdEqualTo(roleId);
        int i1 = roleMenuMapper.deleteByExample(ahe);
        return true;
    }

    @Override
    public List<Integer> selectnraandactor(Integer pid) {
        return personRoleMapper.selectbynidsome(pid);
    }
}
